$(function () {

    var html_data = {
        baseConfig: baseConfig,
        un_cash_order_index: 1,
        un_cash_order_count: 0,
        un_pay_order_list: [],
        pay_order_list: [],
        pay_order_index: 1,
        pay_order_count: 0,
        order_list: [],
        sessionid: '',
        sessionid_q: '',
        unapply_price: 0,
        apply_price: 0,
        address_info: {},
        cash_list: [],
        has_login: false,
        alipay: "",
        money: 0,
        order_num: 0,
        order_price: 0,
        ping_money: 0,
        cash_money: 0,
        cash_order_num: 0,
        cash_order_price: 0,
        cash_ping_money: 0,
        un_money: 0,
        start_time:null,
        end_time:null


    };
    var app = new Vue({
        el: '#host_cash_page',
        data: html_data,
        methods: {
            price_filter: price_filter,

            query_un_cash_order_info_list: function (i) {
                api.lorder.query_withdraw_cash_info_list({
                    is_pay_paid: false,
                    page_index: html_data.un_cash_order_index+i
                }).then(function (data) {
                    html_data.un_cash_order_index = data.result.page_index;
                    html_data.un_cash_order_count = data.result.page_count;
                    // if (html_data.un_cash_order_index != data.result.page_count) {
                    //     html_data.un_cash_order_index += 1;
                    // }
                    _(data.result.list).each(function (item) {
                        html_data.order_list.push(item);

                    });
                });
            },
            query_pay_order_info_list: function (i) {
                api.lorder.query_withdraw_cash_info_list({
                    is_pay_paid: true,
                    page_index: html_data.pay_order_index+i
                }).then(function (data) {
                    html_data.pay_order_index = data.result.page_index;
                    html_data.pay_order_count = data.result.page_count;
                    // if (html_data.pay_order_index != data.result.page_count) {
                    //     html_data.pay_order_index += 1;
                    // }
                    _(data.result.list).each(function (item) {
                        html_data.pay_order_list.push(item);
                    });
                });
            },


            check_login: function () {
                var defer = $.Deferred();
                api.sys.check_login().then(function (data) {
                    if (data.result.has_login) {
                        client_storage('sessionid', data.result.sessionid);
                        defer.resolve({success: true});
                    } else {
                        Magiclamp.mcLoginPrompt(function (username, password) {
                            api.sys.simple_login({
                                is_live: true,
                                username: username,
                                password: password
                            }).then(function (login_result) {
                                if (login_result.success) {
                                    client_storage('sessionid', login_result.result.sessionid);
                                    defer.resolve({success: true});
                                } else {
                                    defer.reject({success: false});
                                }
                            }, function (data) {
                                defer.reject({success: false});
                            })
                        });
                    }
                }, function () {
                    defer.reject({success: false});
                });
                return defer.promise();
            },
            login_mogu: function () {
                html_data.end_time = moment(new Date()).format("YYYY-MM-DD");
                html_data.start_time = moment().subtract(31, 'days').format("YYYY-MM-DD");
                app.check_login().then(function (data) {
                    if (data.success) {
                        html_data.has_login = true;
                        app.query_pay_order_info_list(0);
                        // app.query_un_cash_order_info_list();
                        app.query_un_cash_order_info_list(0);
                        //
                        // api.sys.get_host_alipay().then(function (data) {
                        //     html_data.user_name = data.result.user_name;
                        //     if (data.result.user_name) {
                        //         app.query_withdraw_cash_apply();
                        //         // app.query_un_cash_order_info_list();
                        //         app.query_withdraw_cash_info_by_date();
                        //     } else {
                        //         location.href = 'host_alipy.html';
                        //     }
                        // });
                    } else {

                        //app.login_mogu();
                    }
                }, function (data) {
                    //app.login_mogu();
                });
            },
            page_back: function () {
                baseConfig.page_back();
            }

        }
    });

    html_data.sessionid = GetQueryString('sessionid');
    if (html_data.sessionid) {
        html_data.sessionid_q = "sessionid=" + html_data.sessionid;
        client_storage('sessionid', html_data.sessionid);
    }

    app.login_mogu();
    // app.query_withdraw_cash_apply();
    // app.query_un_cash_order_info_list();
    //
    //
    var $tags = $('#order-tab').find('a');
    window.mySwipe = new Swipe(document.getElementById('slider'), {
        continuous: false,
        disableScroll: false,
        stopPropagation: false,
        callback: function (index) {
            $tags.eq(index).addClass('tag-on')
                .siblings('a').removeClass('tag-on');
        },
        transitionEnd: function (index, elem) {
        }
    });
    $tags.eq(0).click(function (e) {
        mySwipe.prev();
        e.preventDefault();
    });
    $tags.eq(1).click(function (e) {
        mySwipe.next();
        e.preventDefault();
    });

});